package com.usian.controller;

import com.usian.UserFeign;
import com.usian.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserFeign userFeign;


    @RequestMapping("consumer/findById/{id}")
    public User findById(@PathVariable Integer id){
        return userFeign.findById(id);
    }

    @RequestMapping("consumer/findName")
    public User findName(@RequestParam String name){
        return userFeign.findName(name);
    }

    @RequestMapping("consumer/findUser")
    public void findUser(){
        User user = new User();
        user.setId(15);
        user.setName("张三");
        user.setAge("20");
        userFeign.findUser(user);

    }



    @RequestMapping("consumer/findAll")
    public List findAll(){

       /* ServiceInstance choose = loadBalancerClient.choose("eureka-provider");
        //指定要调用的服务
        String url = "http://"+choose.getHost()+":"+choose.getPort()+"/findAll";
        return restTemplate.getForObject(url, List.class);*/

        return userFeign.findAll();

    }

}
